<template>
    <div>
        <el-container class="container">
            <el-aside width="200px">
                <el-row class="tac">
                    <el-col>
                        <el-menu
                            default-active="2"
                            class="el-menu-vertical-demo menu-box"
                            @open="handleOpen"
                            @close="handleClose"
                            background-color="#545c64"
                            text-color="#fff"
                            active-text-color="#ffd04b"
                            :router="true"
                        >
                            <i class="el-icon-s-grid"></i>
                            <el-submenu index="1">
                                <template slot="title">
                                    <i class="el-icon-location"></i>
                                    <span>车位管理</span>
                                </template>
                                <el-menu-item-group>
                                    <template slot="title"
                                        >车位信息管理</template
                                    >
                                    <el-menu-item
                                        index="/system/ParkingOverview"
                                        >车位信息审核</el-menu-item
                                    >
                                </el-menu-item-group>
                            </el-submenu>
                            <el-submenu index="2">
                                <template slot="title">
                                    <i class="el-icon-location"></i>
                                    <span>出租人管理</span>
                                </template>
                                <el-menu-item-group>
                                    <template slot="title"
                                        >出租人信息管理</template
                                    >
                                    <el-menu-item index="/system/lessorsCheck"
                                        >出租人信息总览</el-menu-item
                                    >
                                </el-menu-item-group>
                            </el-submenu>
                            <el-submenu index="3">
                                <template slot="title">
                                    <i class="el-icon-location"></i>
                                    <span>租客管理</span>
                                </template>
                                <el-menu-item-group>
                                    <template slot="title"
                                        >租客信息管理</template
                                    >
                                    <el-menu-item
                                        index="/system/tenantsOverview"
                                        >租客信息总览</el-menu-item
                                    >
                                    <el-menu-item index="/system/tenantsCheck"
                                        >租客信息审核</el-menu-item
                                    >
                                </el-menu-item-group>
                            </el-submenu>

                            <el-submenu index="4" v-if="token == 'admin'">
                                <template slot="title">
                                    <i class="el-icon-location"></i>
                                    <span>订单管理</span>
                                </template>
                                <el-menu-item-group>
                                    <template slot="title"
                                        >订单信息管理</template
                                    >
                                    <el-menu-item index="/system/allOrders"
                                        >订单</el-menu-item
                                    >
                                </el-menu-item-group>
                            </el-submenu>

                            <el-submenu index="5">
                                <template slot="title">
                                    <i class="el-icon-location"></i>
                                    <span>管理员管理</span>
                                </template>
                                <el-menu-item-group>
                                    <template slot="title"
                                        >管理员信息管理</template
                                    >
                                    <el-menu-item index="/system/adminsOverview"
                                        >管理员信息总览</el-menu-item
                                    >
                                    <el-menu-item index="/system/getLogs"
                                        >日志管理</el-menu-item
                                    >
                                </el-menu-item-group>
                            </el-submenu>
                        </el-menu>
                    </el-col>
                </el-row>
            </el-aside>
            <el-container>
                <el-header class="head">
                    <p class="head-p">哈哈车位管理系统</p>
                    <p class="p-width">
                        <img
                            src="../../assets/default.jpg"
                            alt=""
                            class="head-img"
                        />
                        <span class="span"
                            >欢迎您 <i> {{ token }}</i>
                        </span>
                        <button @click="exit" class="button-tuichu">
                            退出
                        </button>
                    </p>
                </el-header>
                <el-main>
                    <router-view :token='token'></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import jwtDecode from "jwt-decode";
import axios from '../../http/axios.js'
export default {
    data() {
        return {
            // 获取登录的用户
            token: "",
            nowId:'',
        };
    },
    mounted() {
        const token = localStorage.getItem("token");
        const decode = jwtDecode(token);
        this.token = decode.account;
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },

        // 退出登录
        exit() {
            axios({
                    url:'/logs/createLogs',
                    method:'post',
                    data:{
                        name:this.token,
                        operation:'退出登录',
                        result:'成功'
                    }
                    })
            this.$confirm("退出登录, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    setTimeout(() => {
                        localStorage.clear(this.token);
                        this.$router.push({ path: "/login" });
                        this.$message({
                            type: "success",
                            message: "已退出登录!",
                        });
                    }, 1000);
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消",
                    });
                });
        },
    },
};
</script>

<style >
html,
body {
    padding: 0px;
    margin: 0px;
}
/* 头部 */
.head {
    display: flex;
}
.head-p {
    width: 67%;
    line-height: 60px;
    padding: 0px;
    margin: 0px;
    font-size: 25px;
    padding-left: 20px;
}
.p-width {
    width: 30%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 105px;
    box-sizing: border-box;
}
.head-img {
    width: 50px;
    vertical-align: middle;
}
.span {
    margin-left: 10px;
}
.button-tuichu {
    width: 50px;
    height: 30px;
    margin-left: 30px;
    background-color: #3e4b58;
    outline: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
}
.container {
    height: 100vh;
}
.el-header,
.el-footer {
    background-color: #3e4b58;
    color: #fff;
    text-align: center;
    line-height: 60px;
}

.el-aside {
    background-color: #d3dce6;
    color: #333;
    text-align: center;
    line-height: 200px;
}

.el-main {
    background-color: white;
    color: #333;
    text-align: center;
}

body > .el-container {
    margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
    line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
    line-height: 320px;
}
.menu-box {
    height: 100vh;
    line-height: 75px;
}

li {
    text-align: left;
}
.el-icon-s-grid {
    margin-top: 10px;
    font-size: 50px;
    color: #d3dce6;
}
.container .el-menu {
    border-right: none;
}
</style>